<template>
  <div class="c-bg-sgray">
    <article v-if="!paySuccess">
      <section v-if="fromType == -2">
        <div class="c-ph24 c-textAlign-c c-fw800 c-fs100 c-pv80">{{'￥' | iosPriceFilter}}{{price}}</div>
        <div class="c-fs26 c-pl24 c-fc-sblack c-bd-b1 c-pv32 c-bg-white">
          <span class="c-mr54">类型</span>购买标准版
        </div>
        <div class="c-fs26 c-pl24 c-fc-sblack c-pv32 c-bg-white c-mb80">
          <span class="c-mr32">收款方</span>创客匠人
        </div>
      </section>
      <section v-else class="c-ph24 c-pt30 c-flex-row c-pb30 c-bd-b1 c-bg-white">
        <div class="c-bd1 c-ww200 c-maxh150 c-text-hidden c-bd1 c-flex-shrink0">
          <img class="c-w100 imgCloseBig" :src="$addXossFilter(shopImg, '')" alt="" />
        </div>
        <div class="c-pl20 c-w0 c-flex-grow1 c-maxh150 c-flex-column c-justify-sa">
          <div class="c-fs28 c-fc-xblack c-ww-bw c-ww-ba">{{shopTitle}}</div>
          <div class="c-fs20 c-fc-sorange">价格：{{'￥' | iosPriceFilter}}{{price}}</div>
        </div>
      </section>
      <div class="c-mt10 c-bd-b1 c-ph24 c-pt28 c-pb20 c-fs28 c-bg-white">支付平台</div>
      <div class="c-bd-b1 c-flex-row c-aligni-center c-hh80 c-ph24 c-bg-white">
        <div class="c-w10 icon iconfont c-fs40 c-fc-green c-lh c-pt4">&#xe61a;</div>
        <div class="c-w80 c-fc-xblack c-fs22 c-lh">微信支付</div>
        <i class="c-w10 c-textAlign-r icon iconfont c-fs32 c-lh c-pt4 c-fc-sorange">&#xe6b1;</i>
      </div>
      <div class="c-mt40 c-mh24 c-pv20 c-fs32 c-textAlign-c c-bg-mgreen c-fc-white" @click="clickBuy">确认支付{{'￥' | iosPriceFilter}}{{price}}</div>
    </article>
    <article class="c-textAlign-c c-fs32 c-pv40 c-ph24" v-if="paySuccess">
      <div class="iconfont c-fc-green c-fs150">&#xe6eb;</div>
      <p class="c-fs40 c-fc-green c-mt40">支付成功!</p>
      <p class="c-fs26 c-fc-xblack c-lh60">请返回电脑端继续操作</p>
    </article>
  </div>
</template>
<script>
import { utilJs } from "@/utils/common.js";
const FROM_DEFAULT_IMG = 'https://kposshzcdn.ckjr001.com/live/2019-11-14/eDyakItLkdHNdYrWl8sPQpgAspxdfHVQsEZh7svB.png?x-oss-process=style/w800';
export default {
  components: {
  },
  data() {
    return {
      fromType: 0, // -1 验证支付 -2 // 版本订购
      isSubmit: true,
      orderId: null,
      price: null,
      packageSize: 0,
      paySuccess: false,
      prodId: null,
      companyId: null,
      packageName: '',
      auId: '',
      shopImg: FROM_DEFAULT_IMG,
      shopTitle: '',
      years: '',
      extId1: ''
    };
  },
  methods: {
    clickBuy(e) {
      //点击立即支付
      if (this.isSubmit) {
        this.isSubmit = false;
        let data = {
          prodId: this.prodId,
          payMoney: this.price,
          prodType: this.fromType,
          usePoint: this.flowPackageDiscount,
          fromInvite: 0,
          companyId: this.companyId,
          extGroupId: this.auId,
          payMethod: 1
        };
        if (this.fromType == 93 && this.taskId) {
          data.orderKey = this.taskId;
        }
        if ((this.fromType == 1000 || this.fromType == 2000) && this.packageSize) { // 购买素材空间,购买高清转码空间
          data.number = this.packageSize; // 购买的空间数量（G）
          data.years = this.years // 购买有效期 年限
          data.extId1 = this.extId1
        }
        let $this = this;
        utilJs.postMethod(
          global.apiurl + "orders/submitOrder",
          data,
          function (res) {
            $this.orderId = res.orderId;
            $this.wePay();
          },
          function () {
            $this.isSubmit = true;
          }
        );
      }
    },
    wePay: function () {
      if (this.orderId != -1) {
        let data = {
          orderId: this.orderId,
          mchId: this._mchId
        };
        let $this = this;
        utilJs.wechatPay(
          data,
          function () {
            $this.isSubmit = true;
            $this.paySuccess = true;
            // $this.$routerGo($this, "replace", { path: "/member/memberIndex" });
          },
          function () {
            $this.isSubmit = true;
          }
        );
      } else {
        this.$showCjToast({
          text: "订单生成失败，请重新提交订单",
          type: "warn",
        });
      }
    },
    goIndex() {
      // 去首页
      this.$routerGo(this, "replace", { path: "" });
    },
    //分享
    wechatShare: function () {
      let title = window.localStorage.getItem("shareTitle");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareUrl =
        window.location.href.split("#")[0] +
        "#/?refereeId=" +
        localStorage.getItem("userId");
      let shareDesc = window.localStorage.getItem("shareDesc");
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function () { });
    },
    //手机端分享
    appShare: function () {
      utilJs.appShareTrue("", "", "", "");
    }
  },
  activated() {
    this.isSubmit = true;
    this.fromType = this.$route.query.from;
    this.price = this.$route.query.price;
    this.taskId = this.$route.query.taskId || '';
    this.prodId = this.$route.query.prodId || -1;
    this.packageSize = this.$route.query.packageSize;
    this.flowPackageDiscount = this.$route.query.flowPackageDiscount ? this.$route.query.flowPackageDiscount : 1;
    this.companyId = this.$route.query.companyId;
    this.packageName = this.$route.query.packageName ? decodeURI(this.$route.query.packageName) : '';
    this.auId = this.$route.query.auId || '';
    this.years = this.$route.query.years || ''; // 购买素材库空间年限
    this.extId1 = this.$route.query.extId1 || ''; // 购买素材库空间的id
    this._mchId = this.$route.query.mchId || '';
    if (this.fromType == -1) {
      this.shopTitle = '升级企业版验证支付专用';
    } else if (this.fromType == 50) {
      //购买直播流量
      this.shopTitle = this.packageSize == 0 ? '购买包年不限流量' : `购买${this.packageSize}G流量包`;
    } else if (this.fromType == 47) {
      //购买短信
      this.shopTitle = `购买${this.packageSize}条短信`;
    } else if (this.fromType == 93) {
      //续费套餐
      this.shopTitle = this.packageName;
    } else if (this.fromType == 1000) {
      //购买空间
      this.shopTitle = `购买${this.packageSize}G素材空间`
    } else if (this.fromType == 2000) {
      //有迹定制，购买高清转码空间
      this.shopTitle = `购买高清转码资源包--${this.packageSize}分钟`
    }
    // this.wechatShare();
    this.$store.commit("updateLoadingStatus", {
      isLoading: false
    });
  }
};
</script>
<style scoped>
</style>


